package dao.impl;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import dao.IStoreDao;
import dao.dto.StoreDepositDTO;
import dao.entity.Store;

@Repository
public class StoreDaoImpl extends GenericDao<Store> implements IStoreDao {

    public StoreDepositDTO getStoreWithDeposit() {
        StringBuilder queryBuilder = new StringBuilder();
        queryBuilder.append("SELECT new " + StoreDepositDTO.class.getName());
        queryBuilder.append("(store.name, deposit.name) ");
        queryBuilder.append(" FROM Store AS store ");
        queryBuilder.append(" JOIN store.deposits AS deposit ");
        queryBuilder.append(" WHERE store.id = 1 ");

        Query query = getSession().createQuery(queryBuilder.toString());

        return (StoreDepositDTO) query.uniqueResult();
    }

}
